package com.dmzc.Recursion;

/**
 * r(n)=r(n-1)+ACCUMULATE
 * r(n-1)=r(n-2)+ACCUMULATE
 * r(n-2)=r(n-3)+ACCUMULATE
 * .......
 * r(3)=r(2)+ACCUMULATE
 * r(2)=r(1)+ACCUMULATE
 * r(1)=1
 * r(1)+r(2)+.....+r(n)=r(1)+....+r(n-1)+1+(n-1)*ACCUMULATE
 * r(n)=1+(n-1)*ACCUMULATE
 */
public class Test1 {
    private static final int RECURSION_TERMINATION = 1;
    private static final int ACCUMULATE = 5;
    public static void main(String[] args) {
        System.out.println(r(45));
    }

    private static int r(int n) {
        if (n == RECURSION_TERMINATION)
            return n;
        return r(n - 1) + ACCUMULATE;
    }
}


